<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>知果汇</title>
    <link href="__STATIC__/admin/css/bootstrap.min.css" rel="stylesheet">
    <!--[if lt IE 9]>
    <script src="__STATIC__/admin/js/html5shiv.min.js"></script>
    <script src="__STATIC__/admin/js/respond.min.js"></script>
    <![endif]-->
    <style type="text/css">
        body {
            background-color: #ffffff;
        }

        .main-box {
            text-align: center;
            font-size: 16px;
        }

        .main-box p {
            text-align: center;
            margin-top: 15px;
        }

        .main-box p span {
            color: #ff2929
        }

        .btn {
            width: 100px;
        }

        .btn-b, .btn-b:hover, .btn-b:focus {
            background-color: #3171b4;
            border-color: #3171b4;
            color: #ffffff;
        }

        .btn-c, .btn-c:hover, .btn-c:focus {
            background-color: #666666;
            border-color: #666666;
            color: #ffffff;
        }
    </style>
</head>
<body>
<div class="main-box">
	<input type="hidden" id="services"/>
    <p id="main-text"></p>
    <p id="main-alipay"></p>
    <p>金额(￥)：<span id="money"></span></p>
    <div class="buttons" style="margin-top: 15px;">
        <a href="javascript: void(0);" class="btn btn-b" onclick="confirm(this)">确认</a>
        <a href="javascript: void(0);" class="btn btn-c" onclick="cancel(this)">取消</a>
    </div>
</div>

<script src="__STATIC__/admin/js/jquery.min.js"></script>
<script src="__STATIC__/admin/js/bootstrap.min.js"></script>
<script type="text/javascript" src="__STATIC__/admin/js/layer/layer.js"></script>
<script type="text/javascript">

    var url = window.location.href;
    id = url.split("#")[1];
    page_id = url.split("#")[2];
    refund = url.split('#')[3];
    $.ajax({
        type: 'GET',
        url: "{:url('api/orders/orders_money')}",
        dataType: 'jsonp',
        jsonp: 'callback',
        data: {id: id,'refund':refund},
        success: function (msg) {
            if (msg.code == 200) {
                $("#money").html(msg.data.money);
                $("#main-alipay").html(msg.data.alipay);
				$('#services').val(msg.data.services);

            } else {
                layer.msg('获取信息不成功!', {icon: 5, time: 2000});
            }
        }
    });
  
    if (refund == 'refund') {
        $("#main-text").text('确定退款给买家么？');
        function confirm(obj) {
			var services = $('#services').val();
			if(services == 1){
			 //传递参数
				$.ajax({
					type: 'GET',
					url: "{:url('api/orders/orders_refund')}",
					dataType: 'jsonp',
					jsonp: 'callback',
					data: {'id': id,'refund':'refund'},
					success: function (msg) {
						if (msg.code == 200) {
							layer.msg('退款成功!', {icon: 1, time: 2000});
							parent.postfile(page_id);
							var index = parent.layer.getFrameIndex(window.name);
							parent.layer.close(index); //关闭弹出层
						} else {
							layer.msg(msg.message, {icon: 5, time: 2000});
						}
					}
				});
            }else{
				//传递参数
				$.ajax({
					type: 'GET',
					url: "{:url('api/alipay/refund')}",
					dataType: 'json',
					//jsonp: 'callback',
					data: {'id': id},
					success: function (msg) {
						if (msg.code == 200) {
							layer.msg('退款成功!', {icon: 1, time: 2000});
							parent.postfile(page_id);
							var index = parent.layer.getFrameIndex(window.name);
							parent.layer.close(index); //关闭弹出层
						} else {
							layer.msg(msg.message, {icon: 5, time: 2000});
						}
					}
				});
			}
            
        }

    } else {
        $("#main-text").text('确定打款给卖家么？');
        function confirm(obj) {
            //传递参数
            $.ajax({
                type: 'GET',
                url: "{:url('api/alipay/account')}",
                dataType: 'jsonp',
                jsonp: 'callback',
                data: {'id': id},
                success: function (msg) {
                    if (msg.code == 200) {
                        layer.msg('打款成功!', {icon: 1, time: 2000});
                        parent.postfile(page_id);
						var index = parent.layer.getFrameIndex(window.name);
					
						parent.layer.close(index); //关闭弹出层
                    } else {
                        layer.msg(msg.message, {icon: 5, time: 2000});
                    }
                }
            });

            
        }
    }


    function cancel(obj) {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index); //关闭弹出层
    }
</script>
</body>
</html>